<template>
  <view v-cloak>
    <city-select
        @cityClick="handleSelect"
        :formatName="formatName"
        :activeCity="activeCity"
        :hotCity="hotCity"
        :obtainCitys="obtainCitys"
        :isSearch="false"
        ref="citys"
    ></city-select>
  </view>
</template>

<script>
  import citySelect from "@/components/city-select/city-select.vue"
  export default {
    components: {citySelect},
    data() {
      return {
        //需要构建索引参数的名称（注意：传递的对象里面必须要有这个名称的参数）
        formatName: 'name',
        //当前城市
        activeCity: null,
        hotCity: [],
        obtainCitys: []
      }
    },
    mounted() {
      this._initData()
      const loca = uni.getStorageSync('position')
      if(loca && loca.name){
        this.activeCity = loca || {}
      }
    },
    methods: {
      handleSelect(item) {
        uni.setStorageSync('selectStore',undefined)
        uni.setStorageSync('cityInfo',{
          latitude:uni.getStorageSync('position').latitude,
          longitude:uni.getStorageSync('position').longitude,
          city:item.cityName,
          ...item
        })
        uni.$emit('changeStore')
        uni.navigateBack()
      },
      ///    network
      _initData(){
        uni.showLoading({
          title:'加载中...'
        })
        this.$get('/merchant/v1/cities','','1').then(res=>{
          if(res.code == '1'){
            this.obtainCitys = res.content.map(res=>{
              return {
                ...res,
                name:res.cityName
              }
            })
          }
        })
      }
    }
  }
</script>

<style lang="less" scoped>

</style>
